using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ExpertSMS.Models;

namespace ExpertSMS.Controllers
{   
    public class StoresController : Controller
    {
        private ExpertSMSContext context = new ExpertSMSContext();

        //
        // GET: /Stores/

        public ActionResult Index()
        {
            return RedirectToAction("Details", new { id = 1 });
        }

        //
        // GET: /Stores/Details/5

        public ViewResult Details(int id)
        {
            Store store = context.Stores.Single(x => x.StoreID == id);
            return View(store);
        }

        //
        // GET: /Stores/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Stores/Create

        [HttpPost]
        public ActionResult Create(Store store)
        {
            if (ModelState.IsValid)
            {
                context.Stores.Add(store);
                context.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(store);
        }
        
        //
        // GET: /Stores/Edit/5
 
        public ActionResult Edit(int id)
        {
            Store store = context.Stores.Single(x => x.StoreID == id);
            return View(store);
        }

        //
        // POST: /Stores/Edit/5

        [HttpPost]
        public ActionResult Edit(Store store)
        {
            if (ModelState.IsValid)
            {
                context.Entry(store).State = EntityState.Modified;
                context.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(store);
        }

        //
        // GET: /Stores/Delete/5
 
        public ActionResult Delete(int id)
        {
            Store store = context.Stores.Single(x => x.StoreID == id);
            return View(store);
        }

        //
        // POST: /Stores/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            Store store = context.Stores.Single(x => x.StoreID == id);
            context.Stores.Remove(store);
            context.SaveChanges();
            return RedirectToAction("Index");
        }
    }
}